package com.quanyan.runningriding.web.running.Admin;

import com.quanyan.api.APIResponse;
import com.quanyan.common.Plugin.PageObj;
import com.quanyan.common.utils.DateUtils;
import com.quanyan.common.utils.StringUtil;
import com.quanyan.common.validation.base.Update;
import com.quanyan.runningriding.entity.vo.run.resp.RunSuggest;
import com.quanyan.runningriding.service.RunSuggestService;
import org.apache.commons.collections.MapUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import java.util.Date;
import java.util.List;
import java.util.Map;

/**
 * @author zhiru.tan
 * @date 2016/9/21 0021
 */
@RestController
@RequestMapping(value = "/admin/api/run")
public class RunSuggestAdminController {
    @Autowired
    private RunSuggestService runSuggestService;
    private Logger logger = LoggerFactory.getLogger(RunSuggestAdminController.class);


    @RequestMapping(value = "/suggestList", method = RequestMethod.POST)
    public APIResponse<PageObj<List<RunSuggest>>> suggestList(@RequestBody Map<String, Object> paramMap) {


        Integer pageNum = MapUtils.getInteger(paramMap, "pageNum");
        Integer pageSize = MapUtils.getInteger(paramMap, "pageSize");
        String userId = MapUtils.getString(paramMap, "userId");
        String nickname = MapUtils.getString(paramMap, "nickname");
        String content = MapUtils.getString(paramMap, "content");
        String startTimeStr = MapUtils.getString(paramMap, "startTime");
        String endTimeStr = MapUtils.getString(paramMap, "endTime");
        Date startTime = null;
        Date endTime = null;
        if (!StringUtil.isBlankOrNull(startTimeStr))
            startTime = DateUtils.strToDate(startTimeStr, DateUtils.DAY_DATE_FORMAT_HH_MM_SS);
        if (!StringUtil.isBlankOrNull(startTimeStr))
            endTime = DateUtils.strToDate(endTimeStr, DateUtils.DAY_DATE_FORMAT_HH_MM_SS);
        PageObj<List<RunSuggest>> result = runSuggestService.suggestList(userId, nickname, content, startTime, endTime, pageNum, pageSize);
        return APIResponse.returnSuccess(result);
    }

}
